package org.openstreetmap.josm.plugins.cadastre_es;

import java.util.Hashtable;
import java.util.Vector;

import org.openstreetmap.josm.data.osm.Node;

public class VertexMap {
	public Hashtable<Pixel, VertexContainer> vertexsMap = new Hashtable<Pixel, VertexContainer>();
	
	public void put(PolyPixel p) {
		VertexContainer vc = vertexsMap.get(p);
		if (vc == null) {
			vc = new VertexContainer(p);
			vc.put(p);
			vertexsMap.put(new Pixel(p), vc);
		}
		else 
			vc.put(p);
	}
	
	public Vector<PolyPixel> get(Pixel p) {
		VertexContainer vc = vertexsMap.get(p);
		if (vc == null)
			return null;
		return vc.getVertexs();
	}
	
	public void remove(PolyPixel p) {
		VertexContainer vc =  vertexsMap.get(p);
		if (vc != null)
			vc.remove(p);
		else
			System.out.println("Error, "+p.x()+", "+p.y());
		vc =  vertexsMap.get(p);
	}
	
	public boolean isIncluded(Pixel p) {
		VertexContainer vc = vertexsMap.get(p);
		return vc.isIncluded();
	}
	
	public void setIncluded(Pixel p) {
		VertexContainer vc = vertexsMap.get(p);
		vc.setIncluded();
	}
    
    public void setNode(Pixel p, Node n) {
        VertexContainer vc = vertexsMap.get(p);
        if (vc != null)
            vc.setNode(n);
    }
    
    public Node getNode(Pixel p) {
        VertexContainer vc = vertexsMap.get(p);
        if (vc == null)
            return null;
        return vc.getNode();
    }
}
